<template>
    <div>
        <ul class="mui-table-view">
            <li class="mui-table-view-cell mui-media"
                v-for="news in newsList" :key="news.id">
                <router-link :to="'/home/newsinfo/' + news.id">
                    <img class="mui-media-object mui-pull-left"
                         :src="news.img_url">
                    <div class="mui-media-body">
                        <h4 v-text="news.title"></h4>
                        <p class="mui-ellipsis">
                            <span>发表时间：{{ news.add_time | dateFormat }}</span>
                            <span>点击：{{ news.click }}次</span>
                        </p>
                    </div>
                </router-link>
            </li>
        </ul>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui'

    export default {
        data() {
            return {
                newsList: [], //新闻列表数组
            }
        },
        created() {
            this.getNewList()
        },
        methods: {
            getNewList() { //获取新闻列表
                this.$http.get('api/getnewslist').then(res => {
                    if (res.body.status === 0) {
                        this.newsList = res.body.message
                    } else {
                        Toast('新闻列表获取失败！')
                    }
                })
            }
        },
    }
</script>

<style scoped lang="scss">
    .mui-table-view {
        li {
            h4 {
                font-weight: lighter;
                font-size: 15px;
            }

            .mui-ellipsis {
                font-size: 12px;
                color: #84abff;
                display: flex;
                justify-content: space-between;
            }
        }
    }
</style>